/*
 * Input Output Operations (io's) are defined here
 *
 * NOTE: asm -> is for indicating that the following instructions are 
 *  assembly instructions
 *
 * NOTE: volatile -> is to indicate that that the instructions have to be 
 *  executed where we put it (it should not be moved out for optimization)
 *
 */

#include "kernel.h"

/*
 *
 * inb assembly embedded and callable in C
 *
 */
unsigned char inb( unsigned short port )
{
    unsigned char ret;
    asm volatile( "inb %1, %0"
                  : "=a"(ret) : "Nd"(port) );
    return ret;
}

/*
 *
 * inw assembly embedded and callable in C
 *
 */
unsigned short inw(int port)
{
    unsigned short val;
    asm volatile("inw %w1, %0" : "=a" (val) : "dI" (port));
        
    return val;
}
  
/*
 *
 * inl assembly embedded and callable in C
 *
 */
unsigned int inl(int port)
{
    unsigned int val;
    asm volatile("inl %w1, %0" : "=a" (val) : "dI" (port));
      
    return val;
}

/*
 *
 * outb assembly embedded and callable in C
 *
 */
void outb(int port, unsigned char val)
{
    asm volatile("outb %b0, %w1" : : "a" (val), "dI" (port));
}

/*
 *
 * outw assembly embedded and callable in C
 *
 */
void outw(int port, unsigned short val)
{
    asm volatile("outw %w0, %w1" : : "a" (val), "dI" (port));
}

/*
 *
 * outl assembly embedded and callable in C
 *
 */
void outl(int port, unsigned int val)
{
    asm volatile("outl %0, %w1" : : "a" (val), "dI" (port));
}
